//
//  DSTagsView.m
//  DemoTest
//
//  Created by DaShuEdu on 2017/5/10.
//  Copyright © 2017年 DaShuEdu. All rights reserved.
//

#import "DSTagsView.h"
#import "DSTagLabel.h"

@implementation DSTagsView

- (void)viewWithTagArr:(NSArray *)tags
{
    if (tags.count < 1) {
        return;
    }
    for (UIView *subView in self.subviews) {
        [subView removeFromSuperview];
    }
    
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat h = 20;
    for (int i = 0; i<tags.count; i++) {
        NSString *labelStr = tags[i];
        DSTagLabel *tag = [[DSTagLabel alloc] initWithInsets:UIEdgeInsetsMake(4, 5, 4, 5)];
        CGFloat tagW = [tag lableWidthWith:labelStr];
        [self addSubview:tag];
        
        if (x+tagW < self.bounds.size.width) {
            tag.frame = CGRectMake(x, y, tagW, h);
        } else {
            y = y + 30;
            x = 0;
            tag.frame = CGRectMake(x, y, tagW, h);
        }
        x = x + tagW + 10;
        if (i == tags.count - 1) {
            self.tagsViewH = y + 20;
        }
    }
}

@end
